﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

public partial class JCXX_YQXZAdd : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
    if (!Page.IsPostBack)
    {
      if (!ProjectPrivate.GetQX("1"))
      {
        Server.Transfer("~\\blank.aspx");
      }
      string sID = CommonUse.GetID();
      if (!string.IsNullOrEmpty(sID))
        InitData(sID);
    }
  }

  protected void InitData(string sID)
  {
    SqlDataReader dr = YQXZ.GetXX(sID);
    if (dr.Read())
    {
      txtName.Text = dr["yqxz"].ToString();
      txtXH.Text = dr["xh"].ToString();
      hlName.Value = txtName.Text;
      hlXH.Value = txtXH.Text;
    }
    dr.Close();
  }

  protected void btnConfirm_Click(object sender, EventArgs e)
  {
    if (string.IsNullOrEmpty(CommonUse.GetID()))
      Insert();
    else
      Update();
  }

  //插入
  protected void Insert()
  {
    if (CommonUse.ExistID("jcxx_yqxz", "yqxz", txtName.Text))
    {
      lbMessage.Text = "此用气性质已存在";
      return;
    }
    string sID = CommonUse.GetID("jcxx_yqxz", "yqxzid");
    Save(sID);
  }

  protected void Save(string sID)
  {
    List<CommandInfo> cis = new List<CommandInfo>();

    cis.Add(CommonUse.DeleteCI("jcxx_yqxz", "yqxzid", sID));

    ArrayList arrValue = new ArrayList();
    arrValue.Add(sID);
    arrValue.Add(txtName.Text);
    arrValue.Add(txtXH.Text);
    ArrayList arrLengh = new ArrayList();
    arrLengh.Add("20");
    arrLengh.Add("20");
    arrLengh.Add("20");
    cis.Add(CommonUse.InsertCI("jcxx_yqxz", arrValue, arrLengh));

    if (DbHelperSQL.ExecuteSqlTran(cis) > 0)
    {
      lbMessage.Text = txtName.Text + "保存成功";
      if (CommonUse.GetID() != "")
      {
        string nr = "";
        if (txtName.Text != hlName.Value)
          nr += "名称由" + hlName.Value + "改为" + txtName.Text + "  ";
        if (txtXH.Text != hlXH.Value)
          nr += "序号由" + hlXH.Value + "改为" + txtXH.Text + "  ";
        if (nr != "")
          rzcz.InsertRZ("修改用气性质:" + nr);
        InitData(sID);
      }
    }

  }

  //修改
  protected void Update()
  {
    Save(CommonUse.GetID());
  }
}
